package com.learning.platform.dto;

import com.learning.platform.entity.Note;
import com.learning.platform.enums.NoteType;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 笔记响应DTO
 */
public class NoteResponse {
    
    private Long id;
    private Long userId;
    private Long courseId;
    private Long lessonId;
    private Integer videoTimestamp;
    private String title;
    private String content;
    private List<String> tags;
    private NoteType noteType;
    private Boolean isPublic;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    
    // 扩展字段
    private String courseTitle;
    private String lessonTitle;
    private String formattedTimestamp;
    
    // Constructors
    public NoteResponse() {}
    
    public NoteResponse(Note note) {
        this.id = note.getId();
        this.userId = note.getUserId();
        this.courseId = note.getCourseId();
        this.lessonId = note.getLessonId();
        this.videoTimestamp = note.getVideoTimestamp();
        this.title = note.getTitle();
        this.content = note.getContent();
        this.tags = note.getTags();
        this.noteType = note.getNoteType();
        this.isPublic = note.getIsPublic();
        this.createdAt = note.getCreatedAt();
        this.updatedAt = note.getUpdatedAt();
        
        // 格式化时间戳
        if (this.videoTimestamp != null) {
            this.formattedTimestamp = formatTimestamp(this.videoTimestamp);
        }
    }
    
    /**
     * 格式化视频时间戳为可读格式
     */
    private String formatTimestamp(Integer seconds) {
        if (seconds == null || seconds < 0) {
            return null;
        }
        
        int hours = seconds / 3600;
        int minutes = (seconds % 3600) / 60;
        int secs = seconds % 60;
        
        if (hours > 0) {
            return String.format("%02d:%02d:%02d", hours, minutes, secs);
        } else {
            return String.format("%02d:%02d", minutes, secs);
        }
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getUserId() {
        return userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public Long getCourseId() {
        return courseId;
    }
    
    public void setCourseId(Long courseId) {
        this.courseId = courseId;
    }
    
    public Long getLessonId() {
        return lessonId;
    }
    
    public void setLessonId(Long lessonId) {
        this.lessonId = lessonId;
    }
    
    public Integer getVideoTimestamp() {
        return videoTimestamp;
    }
    
    public void setVideoTimestamp(Integer videoTimestamp) {
        this.videoTimestamp = videoTimestamp;
        this.formattedTimestamp = formatTimestamp(videoTimestamp);
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getContent() {
        return content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    public List<String> getTags() {
        return tags;
    }
    
    public void setTags(List<String> tags) {
        this.tags = tags;
    }
    
    public NoteType getNoteType() {
        return noteType;
    }
    
    public void setNoteType(NoteType noteType) {
        this.noteType = noteType;
    }
    
    public Boolean getIsPublic() {
        return isPublic;
    }
    
    public void setIsPublic(Boolean isPublic) {
        this.isPublic = isPublic;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    public String getCourseTitle() {
        return courseTitle;
    }
    
    public void setCourseTitle(String courseTitle) {
        this.courseTitle = courseTitle;
    }
    
    public String getLessonTitle() {
        return lessonTitle;
    }
    
    public void setLessonTitle(String lessonTitle) {
        this.lessonTitle = lessonTitle;
    }
    
    public String getFormattedTimestamp() {
        return formattedTimestamp;
    }
    
    public void setFormattedTimestamp(String formattedTimestamp) {
        this.formattedTimestamp = formattedTimestamp;
    }
}
